package com.itheima.controller;

import com.itheima.pojo.PmsSkuStock;
import com.itheima.service.PmsSkuStockService;
import com.itheima.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.aggregation.ArrayOperators;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sku")
public class PmsSkuStockController {

    @Autowired
    private PmsSkuStockService pmsSkuStockService;

    /**
     * 批量更新sku库存信息
     */
    @PostMapping("/update/{pid}")
    public ResponseEntity update(@PathVariable Integer pid,
                                 @RequestBody List<PmsSkuStock> skuStockList){
        pmsSkuStockService.update(pid,skuStockList);
        return ResponseEntity.ok(Result.success(null));
    }


    /**
     * 根据商品id以及sku编码模糊查询sku库存
     */
    @GetMapping("/{pid}")
    public ResponseEntity findByPid(@PathVariable Integer pid,
                                   String keyword){
        List<PmsSkuStock> pmsSkuStockList = pmsSkuStockService.findByPid(pid,keyword);
        return ResponseEntity.ok(Result.success(pmsSkuStockList));
    }

}
